<template>
    <el-container style="height: 800px; border: 1px solid #eee">
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
            <el-menu>
                <el-submenu :index="permission.id" v-for="permission in permissions">
                    <template slot="title">{{permission.name}}</template>
                    <el-menu-item :index="child.id" v-for="child in permission.childPermissions" v-if="child.url!=null">
                        <router-link :to="child.url">{{child.name}}</router-link>
                    </el-menu-item>
                </el-submenu>
            </el-menu>
        </el-aside>

        <el-container>
            <el-header style="text-align: right; font-size: 12px">
                <el-dropdown>
                    <i class="el-icon-setting" style="margin-right: 15px"></i>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>查看</el-dropdown-item>
                        <el-dropdown-item>新增</el-dropdown-item>
                        <el-dropdown-item>删除</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <span>{{username}}</span>
            </el-header>

            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "MainView",
        data(){
            return {
                username:"",
                permissions:[] //权限菜单
            }
        },
        mounted() {
            this.username = localStorage.getItem("username");
            this.axios.get("user-permission-menus/" + this.username)
                .then(result => {
                    if(result.data.code == 200){
                        this.permissions = result.data.data;
                        console.log(this.permissions)
                    }
                })
        }
    }
</script>

<style scoped>
    .el-header {
        background-color: #B3C0D1;
        color: #333;
        line-height: 60px;
    }

    .el-aside {
        color: #333;
    }

    a{
        text-decoration: none;
        color:#333;
    }
</style>
